import { request, config } from 'utils';
import { stringify } from 'qs';
const {
  api: {
    recursivemgt: {
      transpond: {
        apigetalldevices,
        apiaddcache,
        apiupdatecache,
        apigetcache,

        apigettranspondlist,
        apiaddtranspond,
        apiupdatetranspond,
        apideletetranspond,
        apifreshconfig
      },
    },
    domain: {
      domain: { apigetallgrouplist },
    },
  },
} = config;

export function getAllDevices(params) {
  return request(`${apigetalldevices}?${stringify(params)}`);
}

export function getAllDomainGroup(params) {
  return request(`${apigetallgrouplist}?${stringify(params)}`);
}

export function getCache(params) {
  return request(`${apigetcache}?${stringify(params)}`);
}

export function addCache(params) {
  return request(apiaddcache, {
    method: 'POST',
    body: { ...params },
  });
}

export function updateCache(params) {
  return request(apiupdatecache, {
    method: 'POST',
    body: { ...params },
  });
}

/**
 * 转发
 */

export function getTranspondList(params) {
  return request(`${apigettranspondlist}?${stringify(params)}`);
}

export function addTranspond(params) {
  return request(apiaddtranspond, {
    method: 'POST',
    body: { ...params },
  });
}

export function updateTranspond(params) {
  return request(apiupdatetranspond, {
    method: 'POST',
    body: { ...params },
  });
}

export function deleteTranspond(params) {
  return request(apideletetranspond, {
    method: 'POST',
    body: { ...params },
  });
}

export function freshConfig(params) {
  return request(`${apifreshconfig}?${stringify(params)}`);
}
